package tw.asap.plus.entity.response;

import java.util.ArrayList;
import java.util.List;

import tw.asap.plus.entity.CartBean;
import tw.asap.plus.entity.SubCartBean;
import tw.asap.plus.entity.request.CommonRequestParams;

/**
 * Created by Yax.
 * Date: 15/11/14
 * Time: 上午1:51
 * Description:
 */
public class OrderCreate extends CommonRequestParams {


    /**
     * shopkey : 店铺id
     * addr_id : 订单地址id
     * order_memo : 订单备注
     * order_lat : 纬度
     * order_lng : 经度
     * items : [{"item_id":"商品id","item_nums":"商品数量"}]
     * coupon_sn : 优惠卷id
     */

    private String shopkey;
    private String addr_id;
    private String order_memo;
    private String order_lat;
    private String order_lng;
    private String coupon_sn;
    /**
     * item_id : 商品id
     * item_nums : 商品数量
     */
    private List<ItemsEntity> items;

    public void setShopkey(String shopkey) {
        this.shopkey = shopkey;
    }

    public void setAddr_id(String addr_id) {
        this.addr_id = addr_id;
    }

    public void setOrder_memo(String order_memo) {
        this.order_memo = order_memo;
    }

    public void setOrder_lat(String order_lat) {
        this.order_lat = order_lat;
    }

    public void setOrder_lng(String order_lng) {
        this.order_lng = order_lng;
    }

    public void setCoupon_sn(String coupon_sn) {
        this.coupon_sn = coupon_sn;
    }

    public void setItems(List<ItemsEntity> items) {
        this.items = (List<ItemsEntity>) items;
    }

    public void setCartBeans(List<CartBean> cartBeans) {
        items = new ArrayList<>();
        for (CartBean bean : cartBeans) {

            if (bean.goodsInfo.hasSub && bean.goodsInfo.subList != null && bean.goodsInfo.subList.size() > 0) {
                for (SubCartBean subCartBean : bean.goodsInfo.subList) {
                    ItemsEntity item = new ItemsEntity();
                    item.item_id = bean.item_id;
                    item.props = new ArrayList<>();
                    item.props.clear();
                    for (String key : subCartBean.getPropertyMap().keySet()) {
                        PropertyEntity entity = new PropertyEntity();
                        entity.propkey_id = key;
                        entity.propvalue_id = subCartBean.getPropertyMap().get(key).getPropvalue_id();
                        item.props.add(entity);
                    }
                    item.setItem_nums(String.valueOf(subCartBean.getCount()));
                    items.add(item);
                }
            } else {
                ItemsEntity item = new ItemsEntity();
                item.item_id = bean.item_id;
                item.item_nums = bean.item_nums;
                items.add(item);
            }
        }
    }

    public String getShopkey() {
        return shopkey;
    }

    public String getAddr_id() {
        return addr_id;
    }

    public String getOrder_memo() {
        return order_memo;
    }

    public String getOrder_lat() {
        return order_lat;
    }

    public String getOrder_lng() {
        return order_lng;
    }

    public String getCoupon_sn() {
        return coupon_sn;
    }

    public List<ItemsEntity> getItems() {
        return items;
    }

    public static class ItemsEntity {
        public String item_id;
        public String item_nums;
        public List<PropertyEntity> props;


        public List<PropertyEntity> getProps() {
            return props;
        }

        public void setProps(List<PropertyEntity> props) {
            this.props = props;
        }

        public void setItem_id(String item_id) {
            this.item_id = item_id;
        }

        public void setItem_nums(String item_nums) {
            this.item_nums = item_nums;
        }

        public String getItem_id() {
            return item_id;
        }

        public String getItem_nums() {
            return item_nums;
        }
    }

    public static class PropertyEntity {
        public String propkey_id;
        public String propvalue_id;
    }
}
